﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NFit.Core.Errors;
using NFit.Core.BaseClasses;

namespace NFit.Core
{
    /// <summary>
    /// Represent a row of a fixture
    /// </summary>
    [Serializable]
    public class FixtureRow : RunnableList<FixtureCell>
    {
        /// <summary>
        /// List of the cells of the row
        /// </summary>
        public IList<FixtureCell> Cells
        {
            get { return ChildElements; }
        }

        #region Constructors
        /// <summary>
        /// Constructor
        /// </summary>
        public FixtureRow()
        {            
        }

        /// <summary>
        /// Constructor that create cells from cells's text
        /// </summary>
        /// <param name="cellsText"></param>
        public FixtureRow(string[] cellsText)
        {
            foreach(string s in cellsText)
            {
                AddCell(s);
            }
        }
        #endregion        

        /// <summary>
        /// Add a cell with the provided text
        /// </summary>
        /// <param name="txt"></param>
        public FixtureCell AddCell(string txt)
        {
            FixtureCell cell = new FixtureCell {Text = txt};
            Cells.Add(cell);
            return cell;
        }

        /// <summary>
        /// Add a cell with the provided expected value
        /// </summary>
        /// <param name="expectedValue"></param>
        public FixtureCell AddCell(object expectedValue)
        {
            FixtureCell cell = new FixtureCell {ExpectedValue = expectedValue};
            Cells.Add(cell);
            return cell;
        }

        /// <summary>
        /// Get an array from cells text, starting at the provided cell index
        /// </summary>
        /// <param name="fromIndex">index of the first cell to pick for building the array</param>
        /// <returns>An array of cell's text</returns>
        public string[] GetArray(int fromIndex)
        {
            string[] res = new string[Count - fromIndex];
            for (int i=fromIndex; i<Count ; i++)
            {
                res[i-fromIndex] = this[i].Text;
            }
            return res;
        }
    }
}
